﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GatewayInspect.Common;
using System.Text.RegularExpressions;

namespace GatewayInspect.Modules
{
    public partial class AQGZPTPwdModifyForm : Form
    {
        public AQGZPTPwdModifyForm()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtNewPwd.Text))
            {
                MessageBox.Show("新密码不能为空！");
                return;
            }
            if (!IsNumeric(txtNewPwd.Text))
            {
                MessageBox.Show("告知平台退出密码只能是数字！");
                return;
            }
            string strSql = "update T_SAFETY_INFORM_SETTING set PASSWORD = '" + txtNewPwd .Text+ "' where ORGCODE = '"+Session.CurrentOrgCode+"'";
            DataAccess.ExecuteNonQuery(strSql);
            this.DialogResult = DialogResult.OK;
        }

        private bool IsNumeric(string str)
        {
            Regex reg = new System.Text.RegularExpressions.Regex("^[0-9]+$");
            return reg.IsMatch(str);
        }

        private void AQGZPTPwdModifyForm_Load(object sender, EventArgs e)
        {
            object objPwd = DataAccess.ExecuteScalar("select PASSWORD from T_SAFETY_INFORM_SETTING where ORGCODE = '" + Session.CurrentOrgCode + "'");
            if (objPwd != null && objPwd != DBNull.Value)
            {
                this.txtOldPwd.Text = objPwd.ToString();
            }
        }
    }
}
